// component/step/step.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    unit: String,
    value: Number
  },

  /**
   * 组件的初始数据
   */
  data: {},

  ready() {
    if (!this.data.value) {
      this.setData({
        value: 1
      })
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    numChannge(e) {
      this.setData({
        value: e.detail.value == 0 ? 1 : e.detail.value
      })
      this.triggerEvent('numChange', this.data.value)
    },
    add() {
      this.setData({
        value: this.data.value + 1
      })
      this.triggerEvent('numChange', this.data.value)
    },
    sub() {
      this.setData({
        value: this.data.value - 1 < 1 ? 1 : this.data.value - 1
      })
      this.triggerEvent('numChange', this.data.value)
    },
    getNum() {
      return this.data.value
    },
    setNum(e) {
      this.setData({
        value: e
      })
    },
  }
})